package models

import (
	"app/conf"
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

var (
	DB  *gorm.DB
	err error
)

func ConfigInit() {
	appConf := conf.Conf.MysqlConfig
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True", appConf.User, appConf.Password, appConf.Host, appConf.Port, appConf.Database)
	DB, err = gorm.Open(mysql.Open(dsn))
	if err != nil {
		fmt.Println("mysql连接成功")
		return
	}
	err = DB.AutoMigrate(&Order{})
	if err != nil {
		fmt.Println("数据库迁移失败")
		return
	}
	fmt.Println("数据库迁移成功")
	fmt.Println("mysql连接成功")
}
